import {getList} from '@/api/crud.js'
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
export default{
	mixins:[MescrollMixin],
	data(){
		return {
			dataList:[],
			totalElements:0,
			canReset:false
		}
	},
	onShow(){
		this.canReset && this.downCallback();
		this.canReset = true;
	},
	methods: {
		upCallback(page) {
			const form = {
				...this.form,
				page: page.num,
				size: page.size
			};
			if (this.$store.getters.loginForm) {
				const {uid, userType} = this.$store.getters.loginForm;
				form.uid = uid
				if (!form.userType) form.userType = userType
			}
			getList(form, this.apiType, this.apiModule, this.name).then(res => {
				const curPageData = res.content;
				// 设置列表数据
				if (page.num == 0) this.dataList = []; //如果是第一页需手动制空列表
				this.totalElements = res.totalElements;
				this.mescroll.endBySize(curPageData.length, res.totalElements)
				this.dataList = [...this.dataList, ...curPageData]; //追加新数据
				this.dataListCallBack && this.dataListCallBack(res) //重组数据
				this.sort()
			}).catch(res => {
				this.mescroll.endErr()
			})
		},
	}
}